using Mathmall.Administration.common;
using Mathmall.Administration.Models;
using Mathmall.Administration.Service;
using Mathmall.Administration.Vo;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Mathmall.Administration.Controllers;

[ApiController]
[Route("api/[controller]")]
public class AttrGroupController : ControllerBase
{
    private readonly IAttrGroupService _attrGroupService;

    public AttrGroupController(IAttrGroupService attrGroupService)
    {
        _attrGroupService = attrGroupService;
    }

    /// <summary>
    /// 新增属性分组
    /// </summary>
    /// <param name="attrGroupVo"></param>
    /// <returns></returns>
    // [Authorize(Policy = "AddAttr")]
    [HttpPost]
    public async Task<int> AddAttrGroup(AttrGroupVo attrGroupVo)
    {
        return await _attrGroupService.AddAttrGroup(attrGroupVo);
    }

    /// <summary>
    /// 分页查询属性分组
    /// </summary>
    /// <param name="pageIndex"></param>
    /// <param name="pageSize"></param>
    /// <param name="catalogID"></param>
    /// <param name="condition"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<PaginatedList<AttrGroupVo>> PaginatedQueryAttrGroups(int pageIndex, int pageSize, int catalogID,
        string condition = "")
    {
        return await _attrGroupService.PaginatedQuery(pageIndex, pageSize, condition, catalogID);
    }

    /// <summary>
    /// 根据id查询属性分组信息
    /// </summary>
    /// <param name="attrGroupId"></param>
    /// <returns></returns>
    [HttpGet("{attrGroupId}")]
    public async Task<AttrGroupVo> GetAttrGroups(int attrGroupId)
    {
        AttrGroupVo attrGroupVo = await _attrGroupService.GetAttrGroupById(attrGroupId);
        return attrGroupVo;
    }

    /// <summary>
    /// 修改属性分组
    /// </summary>
    /// <param name="attrGroupVo"></param>
    /// <returns></returns>
    [HttpPut]
    public async Task<int> UpdateAttrGroup(AttrGroupVo attrGroupVo)
    {
        return await _attrGroupService.UpdateAttrGroup(attrGroupVo);
    }

    /// <summary>
    /// 删除属性分组
    /// </summary>
    /// <param name="attrGroupIDs"></param>
    /// <returns></returns>
    [HttpDelete]
    public async Task<int> DeleteAttrGroup(List<int> attrGroupIDs)
    {
        return await _attrGroupService.DeleteAttrGroup(attrGroupIDs);
    }
}